import { createRouter, createWebHistory } from 'vue-router'
import Login from '../views/Login.vue'
import Dashboard from '../views/Dashboard.vue'
import ProductManagement from '../views/ProductManagement.vue'
import RegionManagement from '../views/RegionManagement.vue'
import StoreManagement from '../views/StoreManagement.vue'
import EmployeeManagement from '../views/EmployeeManagement.vue'
import MarketingStrategyManagement from '../views/MarketingStrategyManagement.vue'

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/dashboard',
    name: 'Dashboard',
    component: Dashboard,
    meta: { requiresAuth: true }
  },
  {
    path: '/products',
    name: 'ProductManagement',
    component: ProductManagement,
    meta: { requiresAuth: true }
  },
  {
    path: '/regions',
    name: 'RegionManagement',
    component: RegionManagement,
    meta: { requiresAuth: true }
  },
  {
    path: '/stores',
    name: 'StoreManagement',
    component: StoreManagement,
    meta: { requiresAuth: true }
  },
  {
    path: '/employees',
    name: 'EmployeeManagement',
    component: EmployeeManagement,
    meta: { requiresAuth: true }
  },
  {
    path: '/marketing-strategies',
    name: 'MarketingStrategyManagement',
    component: MarketingStrategyManagement,
    meta: { requiresAuth: true }
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {
  const token = localStorage.getItem('token')
  if (to.meta.requiresAuth && !token) {
    next('/login')
  } else {
    next()
  }
})

export default router 